<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->

    <title>文章分类列表</title>
    <!--{include file='comm/icheck.tpl'}-->
</head>
<body>

<div class="container">

  
    <div class="comm_content">
        <table id="flex" style="display:none"></table>
    </div>

</div>

<div id="pop" style="display: none">

    <div style="width:100%">

        <form id="article_form" onsubmit="return false;" class="form-horizontal">

            <input type="hidden" id="category_id" name="category_id" value="0" />

            <div class="form-group">
                <label class="col-sm-3 control-label" for="category_index">
                    <span class="red">*</span>
                    分类别名：
                </label>
                <div class="col-sm-9">
                    <input type="text" value="" maxlength="20" placeholder="请输入分类别名" class="form-control w300" id="category_index" name="category_index" style="ime-mode:active" />
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label" for="category_title">
                    <span class="red">*</span>
                    分类标题：
                </label>
                <div class="col-sm-9">
                    <input type="text" class="form-control w300" placeholder="请输入分类标题" id="category_title" name="category_title" maxlength="200" value="">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label" for="category_type">
                    <span class="red">*</span>
                    分类类型：
                </label>
                <div class="col-sm-9">
                    <select class="form-control w150" id="category_type" name="category_type">
                        <option value="">请选择</option>
                        <option value="1">帮助文章</option>
                        <option value="2">公告文章</option>
                        <option value="3">新闻文章</option>
                    </select>
                </div>
            </div>



            <div class="form-group">
                <label class="col-sm-3 control-label" for="description">
                    描述：
                </label>
                <div class="col-sm-9">
                    <textarea class="form-control w300"  placeholder="请输入描述" id="description" name="description"></textarea>
                </div>
            </div>
        </form>
    </div>

</div>

<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/content/articleCategory.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 100, align: "center"},
            {display: "分类号", name : "category_id", width : 100, sortable : true},
            {display: "分类标题", width : 260},
            {display: "分类别名", width : 100},
            {display: "分类类型", width : 100},
            {display: "描述", width : 360},
            {display: "使用标志", width : 70, align: "center"}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "article.edit.open"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "article.deleteArticle"},
            {separator: true},
            {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
            {separator: true},
            {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
        ],
        sortname: "category_id",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var article = {

        //查询
        search: function () {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        edit:{
            open: function( category_id ) {

                if (!category_id) {
                    category_id = 0;
                }else{
                    this.category_id = category_id;
                }

                E.popup.open({
                    id: 'pop',
                    title: category_id == 0 ? '添加文章分类' : '修改文章分类',
                    css: 'width: 600px;',
                    btnName: '保存',
                    btnCall: 'article.edit.check();'
                });

                $('.square-radio').iCheck({
                    checkboxClass: 'icheckbox_square-blue',
                    radioClass: 'iradio_square-blue',
                    increaseArea: '20%' // optional
                });

                if (category_id > 0) {

                    E.ajax_get({
                        url: '/invokingAjax-backend/content/articleCategory.ajax?operFlg=2',
                        data: {
                            category_id: category_id
                        },
                        call: function( o ) {

                            if (o.code == 200) {

                                $('#category_id').val(o.data.category_id);
                                $('#category_index').val(o.data.category_index);
                                $('#category_title').val(o.data.category_title);
                                $('#description').val(o.data.description);
                                $('#category_type').val(o.data.category_type);
                                $('#useFlg-' + o.data.useFlg).iCheck('check');

                            }
                        }
                    });

                }

            },

            check: function() {

                this.dt = E.getFormValues('article_form');

                var error_msg = '';

                if (E.isEmpty(this.dt.category_index))
                    error_msg += '分类别名不能为空<br/>';

                if (E.isEmpty(this.dt.category_title))
                    error_msg += '分类标题不能为空<br/>';

                if (this.dt.category_type == '')
                    error_msg += '请选择分类类型<br/>';

                if (error_msg != '') {
                    E.alert(error_msg);

                } else {
                    if( this.category_id ){
                        E.confirm('您确认修改分类文章吗？', 'article.edit.execute');
                    }else{
                        E.confirm('您确认添加分类文章吗？', 'article.edit.execute');
                    }


                }

            },

            execute: function() {

                E.loadding.open('正在保存，请稍候...');

                E.ajax_post({
                    url: '/invokingAjax-backend/content/articleCategory.ajax?operFlg=100&act=edit',
                    data: this.dt,
                    call: 'article.edit.result'
                });

            },

            result: function( o ) {

                E.loadding.close();

                if (o.code == 200) {

                    if (this.dt.category_id > 0) {
                        E.popup.close();
                    } else {
                        document.getElementById('article_form').reset();
                    }

                    E.alert(o.message, 2, 'article.load');
                } else {
                    E.alert(o.message);
                }

            }

        },

        //重新加载页面内容
        load: function() {
            $("#flex").flexReload();
        },

        delete_str: "",

        deleteArticle: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    article.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择删除文章分类");
            else
                E.confirm("您确认要删除选中的文章分类吗？", "article.deleteConfirm");
        },

        deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/content/articleCategory.ajax?operFlg=100&act=del&delete_str=" + article.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "article.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        change: {

            check: function( category_id, flg ) {

                this.category_id = category_id;
                this.flg = flg;
                if (flg) {
                    E.confirm('您确认禁用该文章分类吗？', 'article.change.execute');
                } else {
                    E.confirm('您确认启用该文章分类吗？', 'article.change.execute');
                }

            },

            execute: function() {

                E.ajax_get({
                    url: '/invokingAjax-backend/content/articleCategory.ajax?operFlg=100&act=change',
                    data: {
                        category_id: this.category_id,
                        flg: this.flg
                    },
                    call: 'article.change.result'
                });

            },

            result: function( o ) {

                if (o.code == 200) {
                    E.alert(o.message, 2, 'article.load');
                } else {
                    E.alert(o.message);
                }

            }

        }

    };
</script>

</body>
</html>